<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<?php $this->load->view('head'); ?>
	<script type="text/javascript" src="<?php echo site_url(); ?>assets/js/upload.js"></script>
	<script type="text/javascript">
		jQuery(document).ready(function() {
			jQuery("#ajaxAdd").ajaxForm({
				dataType:  'json',
				success: function(response) {
					jQuery(".pagePreloader, img.pagePreloaderImg").remove();
					
					var newJobHTML = '<div class="wrapper-world" style="display: none;" id="job_'+ response.job.id +'"><div class="wrapper">';
					if (response.job.ext == "doc")
						newJobHTML += '<div class="file-type type-doc">MS Word file</div>';
					else if (response.job.ext == "img")
						newJobHTML += '<div class="file-type type-img">Image file</div>';
					else if (response.job.ext == "txt")
						newJobHTML += '<div class="file-type type-txt">Text file</div>';
					else if (response.job.ext == "xls")
						newJobHTML += '<div class="file-type type-xls">MS Excel file</div>';
					else if (response.job.ext == "pdf")
						newJobHTML += '<div class="file-type type-pdf">Adobe Reader file</div>';
					else if (response.job.ext == "other")
						newJobHTML += '<div class="file-type type-other">Other type</div>';
					
					newJobHTML += '<div class="file-size">' + response.job.filesize + ' B</div>';
					newJobHTML += '<div class="job-details"><a href="' + siteurl + 'download/' + response.job.id + '" target="_blank">' + response.job.origname + '</a></div>';
					newJobHTML += '<div class="job-delete"><a href="javascript:deleteJob(' + response.job.id + ');" title="Delete job order">Delete</a></div>';
					newJobHTML += '<div class="clr"></div></div></div>';
					jQuery("div.job-listing").prepend(newJobHTML);
					recalcOddEven("div.job-listing div.wrapper-world");
					jQuery("div.job-listing div.wrapper-world:first-child").fadeIn("slow");
				}
			});
		});
	</script>
</head>

<body>
	<?php
	if ($user->id > 0) {
		$this->load->view('header_logged.php');
	} else {
		$this->load->view('header_guest.php');
	}
	?>
	
	<!-- Content Area -->
	<div class="wrapper-world content">
		<div class="wrapper">
			<h1>Book a Bus by Uploading an Itinerary</h1>
			
			<div class="right-half">
				<div class="info-box">
					<div id="info-text" class="info-text">
						If you already have an itinerary ready at hand and do not relish the prospect of filling out all the information again, please upload your itinerary with us and we will provide a quotation based on your document.
					</div>
				</div>
			</div>
			
			<div class="left-half">
				<?php echo form_open_multipart('request/ajaxAdd', array('class' => 'standard-form', 'id' => 'ajaxAdd')); ?>
					<div class="one">
						<label>Upload a file</label>
						<div class="file-upload"> 
						    <input type="file" size="24" name="userfile" id="BrowserHidden" onchange="getElementById('FileField').value = getElementById('BrowserHidden').value;" />			 
						    <div id="BrowserVisible"><input type="text" id="FileField" /></div>
							
							<input type="hidden" name="belongsto" value="<?php echo $orderId; ?>" />
						</div>
						<div class="clr"></div>
					</div>
					<input type="hidden" name="type" value="upload" />
				</form>
			</div>
			
			<div class="clr"></div>
		</div>
	</div> <!-- end of wrapper-world and .content -->
	
	<div class="wrapper-world add-btn">
		<div class="wrapper">
			<a href="javascript:addJobFile();" title="Add this job order">ADD</a>
			<div class="add-info">If you have completed your addition, please click <strong>next</strong> located at the bottom of the page.</div>
			<div class="clr"></div>
		</div>
	</div>
	
	<div class="job-listing">
		<?php $c = 0; foreach ($jobs as $job): ?>
		<div class="wrapper-world job-<?php echo (($c%2 == 0) ? "odd" : "even"); ?>" id="job_<?php echo $job->id; ?>">
			<div class="wrapper">
				<?php if ($job->ext == "doc"): ?>
				<div class="file-type type-doc">MS Word file</div>
				<?php elseif ($job->ext == "img"): ?>
				<div class="file-type type-img">Image file</div>
				<?php elseif ($job->ext == "txt"): ?>
				<div class="file-type type-txt">Text file</div>
				<?php elseif ($job->ext == "xls"): ?>
				<div class="file-type type-xls">MS Excel file</div>
				<?php elseif ($job->ext == "pdf"): ?>
				<div class="file-type type-pdf">Adobe Reader file</div>
				<?php elseif ($job->ext == "other"): ?>
				<div class="file-type type-other">Other type</div>
				<?php endif; ?>
				<div class="file-size"><?php echo $job->filesize; ?> B</div>
				<div class="job-details"><a href="<?php echo site_url(); ?>download/<?php echo $job->id; ?>" target="_blank"><?php echo htmlspecialchars($job->origname); ?></a></div>
				<div class="job-delete"><a href="javascript:deleteJob(<?php echo $job->id; ?>);" title="Delete job order">Delete</a></div>
				<div class="clr"></div>
			</div>
		</div>
		<?php $c++; endforeach; ?>
	</div>
	
	<div class="wrapper">
		<div class="conv-left">
			<div class="avatar"></div>
			<div class="mid"><div class="top"><div class="bot">
			<?php echo form_open('request/jobOrder', array('class' => 'left-aligned', 'id' => 'jobOrder')); ?>
				<input type="hidden" name="draft" value="0" />
				<input type="hidden" name="type" value="upload" />
				<div class="one">
					<label>I would like to supply the following information:</label>
					<div class="type-textarea"><textarea name="moreinfo" id="moreinfo"><?php if ($orderId > 0) { echo htmlspecialchars($jobInfo->moreinfo); } ?></textarea></div>
					<div class="clr"></div>
				</div>
			</form>
			<script type="text/javascript">
				helpTexts['moreinfo'] = 'Please include any additional information / instructions here';
				
				<?php if ($orderId <= 0): ?>
				jQuery("#moreinfo").val(helpTexts['moreinfo']);
				<?php endif; ?>
				
				jQuery("#moreinfo").focus(function() {
					if (jQuery(this).val() == helpTexts['moreinfo']) {
						jQuery(this).val("");
					}
				});
				
				jQuery("#moreinfo").blur(function() {
					if (jQuery(this).val() == "") {
						jQuery(this).val(helpTexts['moreinfo']);
					}
				});
			</script>
			</div></div></div>
			<div class="clr"></div>
		</div>
	</div>
	
	<div class="wrapper">
		<div class="action-buttons">
			<?php
			if ($user->level > 0) {
				$sendText = 'Add Order';
			}
			?>
			<?php if ((!isset($orderId) || !($orderId > 0)) && $user->level < 1): ?><a class="more" href="javascript:jobOrder(1);"><span>Save as draft</span></a> <?php endif; ?><a class="more" href="javascript:jobOrder();"><span><?php echo $sendText; ?></span></a>
		</div>
	</div>
	
	<div class="wrapper-world footer-top">
		<div class="wrapper"></div>	
	</div>
	
	<?php $this->load->view('footer'); ?>
</body>
</html>
